{"id":7256,"date":"2014-10-14T15:16:59","date_gmt":"2014-10-14T19:16:59","guid":{"rendered":"http:\/\/www.gravityhelp.com\/?p=7256"},"modified":"2018-03-29T20:08:14","modified_gmt":"2018-03-29T20:08:14","slug":"gravity-forms-1-9-developer-notes","status":"publish","type":"post","link":"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/","title":{"rendered":"Gravity Forms v1.9 Developer Notes"},"content":{"rendered":"<p>Along with all the much anticipated\u00a0features, Gravity Forms 1.9 brings a number of important changes under the hood that developers need to be aware of. If you're the developer of a Gravity Forms Add-On, or if you have added any customizations at all, please read these notes carefully and make sure you've implemented the suggested changes to your code while 1.9 is still in beta. Some of the changes could result in bugs, fatal errors and white screens if the advice below is not followed.<br \/>\n<!--more--><\/p>\n<h2>1. GFAddOn: No more protected methods<\/h2>\n<p>In response to requests for greater flexibility, and to facilitate customization, we\u2019ve decided to raise the access level for all protected methods to public. This means that all protected\u00a0methods in add-ons that implement the Add-On Framework must also be raised to public to avoid fatal errors under PHP5.4+. So, if your add-on has any protected methods now\u2019s the time to change them all to public - it will work with both 1.8 and 1.9. This change only applies to add-ons that are using the Add-On Framework. Private methods in GFAddOn will remain private and do not need to be changed.<\/p>\n<h2>2. New Field Class: GF_Field<\/h2>\n<p>As of version 1.9, GF_Field is the base class for all fields. It can be found in the includes\/fields folder along with all the classes for the built-in field types each of which extend the base class. All field objects are now instances of GF_Field or one of its child classes.\u00a0This change enables us to keep our code more organised and also provides a more unified way for developers to create new field types.<\/p>\n<h3>Object notation<\/h3>\n<p>When you look through the Gravity Forms code one of the biggest changes you\u2019ll notice immediately is that Field properties are now accessed using <strong>object notation<\/strong> instead of array notation. So, for example, $field[\u2018inputs\u2019] is now written as $field-&gt;inputs. If the property does not exist, an empty string will be returned so you don't need to check that it's set and you don't need to use the rgar() function.\u00a0This means that everywhere you see Field object it's no longer an array, it's now a GF_Field object; this includes all PHP\u00a0actions and filters.\u00a0JavaScript is not affected by this change<\/p>\n<h3>Backwards (and forwards) compatibility<\/h3>\n<p>We've put a lot of effort into ensuring that the legacy array notation will still work, at least for a while. Once everyone has had a chance to change their code, the array notation will trigger a deprecation notice.<\/p>\n<p>There is one important exception to the array notation backwards compatibility; <strong>array values can't be modified indirectly<\/strong>. For example, the following code will generate a 'Indirect modification of overloaded element' notice and will have no effect.<\/p>\n<p><strong>Indirect modification of array values (breaks in 1.9)<\/strong><br \/>\n$field['conditionalLogic']['rules'] = $new_rules;<\/p>\n<p><strong>Works in 1.9 but not in 1.8<br \/>\n<\/strong>$field-&gt;conditionalLogic['rules'] = $new_rules;<\/p>\n<p><strong>Suggested approach (works in both 1.8 and 1.9)<br \/>\n<\/strong>You could either test for the version number or you could copy\u00a0the entire array into a temporary variable, manipulate it and save it back to the field object, something along the lines of this:<br \/>\n$logic = $field['conditionalLogic'];<br \/>\n$logic['rules'] = $new_rules;<br \/>\n$field['conditionalLogic'] = $logic;<\/p>\n<p>The following built-in field properties are arrays, so if you're using them, double check to see if you need to change any code that uses them: inputs, conditionalLogic, choices<\/p>\n<p>GF_Field is still in a state of flux at the moment so we don\u2019t recommend that you start using it just yet as a base for new fields in production environments. Once it\u2019s stable we\u2019ll provide documentation and instructions on how to use it for your own projects.<\/p>\n<h2>3. Form Editor Buttons: Drag &amp; Drop Support<\/h2>\n<p>The field buttons in the Form Editor can now be dragged and dropped onto the Form canvas.\u00a0You no longer need to supply the onclick inline event as StartAddField(<em>type<\/em>) will be triggered automatically. However, you will need to add the type data attribute otherwise a deprecation notice will fire. So for example, if you're using the <a href=\"https:\/\/docs.gravityforms.com\/gform_add_field_buttons\/\">gform_add_field_buttons<\/a> filter you'll need to make the following change:<\/p>\n<p><strong>Legacy Form Editor Button (triggers a deprecation notice)<\/strong><br \/>\n$group['fields'][] = array( 'class' =&gt; 'button', 'value' =&gt; 'Poll', 'onclick' =&gt; \"StartAddField('poll');\" );<\/p>\n<p><strong>New Form Editor Button (Version 1.9 only)<\/strong><br \/>\n$group['fields'][] = array( 'class' =&gt; 'button', 'value' =&gt; 'Poll', 'data-type' =&gt; 'poll' );<\/p>\n<p><strong>Backwards compatible\u00a0Form Editor Button<\/strong><br \/>\n$group['fields'][] = array( 'class' =&gt; 'button', 'value' =&gt; 'Poll', 'data-type' =&gt; 'poll', 'onclick' =&gt; \"StartAddField('poll');\"\u00a0);<\/p>\n<h2>Developer Support<\/h2>\n<p>We do appreciate that these are some fairly major changes and it might require\u00a0some significant effort from some developers to change their code. We'd like to support you to make sure your\u00a0migration is as smooth and painless as possible. so if you have any questions, don't hesitate to send us a support request. Please don't use the comments here for support.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Along with all the much anticipated&nbsp;features, Gravity Forms 1.9 brings a number of important changes under the hood that developers need to be aware of. If you&#8217;re the developer of a Gravity Forms Add-On, or if you have added any customizations","protected":false},"author":1533,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[216],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v16.5 (Yoast SEO v16.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Gravity Forms v1.9 Developer Notes | Gravity Forms<\/title>\n<meta name=\"description\" content=\"Along with all the much anticipated\u00a0features, Gravity Forms 1.9 brings a number of important changes under the hood that developers need to be aware of.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Gravity Forms v1.9 Developer Notes\" \/>\n<meta property=\"og:description\" content=\"Along with all the much anticipated\u00a0features, Gravity Forms 1.9 brings a number of important changes under the hood that developers need to be aware of.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/\" \/>\n<meta property=\"og:site_name\" content=\"Gravity Forms\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GravityForms\" \/>\n<meta property=\"article:published_time\" content=\"2014-10-14T19:16:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-29T20:08:14+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GravityForms\" \/>\n<meta name=\"twitter:site\" content=\"@GravityForms\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.gravityforms.com\/#organization\",\"name\":\"Gravity Forms\",\"url\":\"https:\/\/www.gravityforms.com\/\",\"sameAs\":[\"https:\/\/www.facebook.com\/GravityForms\",\"https:\/\/twitter.com\/GravityForms\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.gravityforms.com\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2018\/06\/gravity_forms_logo.jpg\",\"contentUrl\":\"https:\/\/www.gravityforms.com\/wp-content\/uploads\/2018\/06\/gravity_forms_logo.jpg\",\"width\":268,\"height\":294,\"caption\":\"Gravity Forms\"},\"image\":{\"@id\":\"https:\/\/www.gravityforms.com\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.gravityforms.com\/#website\",\"url\":\"https:\/\/www.gravityforms.com\/\",\"name\":\"Gravity Forms\",\"description\":\"WordPress Contact Forms\",\"publisher\":{\"@id\":\"https:\/\/www.gravityforms.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.gravityforms.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/#webpage\",\"url\":\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/\",\"name\":\"Gravity Forms v1.9 Developer Notes | Gravity Forms\",\"isPartOf\":{\"@id\":\"https:\/\/www.gravityforms.com\/#website\"},\"datePublished\":\"2014-10-14T19:16:59+00:00\",\"dateModified\":\"2018-03-29T20:08:14+00:00\",\"description\":\"Along with all the much anticipated\\u00a0features, Gravity Forms 1.9 brings a number of important changes under the hood that developers need to be aware of.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Gravity Forms\",\"item\":\"https:\/\/www.gravityforms.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"News &amp; Updates\",\"item\":\"https:\/\/www.gravityforms.com\/category\/news\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Gravity Forms v1.9 Developer Notes\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/#webpage\"},\"author\":{\"@id\":\"https:\/\/www.gravityforms.com\/#\/schema\/person\/b4248dc0aac3c54d1a5119a9bd34277b\"},\"headline\":\"Gravity Forms v1.9 Developer Notes\",\"datePublished\":\"2014-10-14T19:16:59+00:00\",\"dateModified\":\"2018-03-29T20:08:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/#webpage\"},\"wordCount\":820,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/www.gravityforms.com\/#organization\"},\"articleSection\":[\"News &amp; Updates\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.gravityforms.com\/gravity-forms-1-9-developer-notes\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.gravityforms.com\/#\/schema\/person\/b4248dc0aac3c54d1a5119a9bd34277b\",\"name\":\"Steve Henty\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.gravityforms.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0bb079bc87d324e56b640a96b35124ac?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0bb079bc87d324e56b640a96b35124ac?s=96&d=mm&r=g\",\"caption\":\"Steve Henty\"},\"url\":\"https:\/\/www.gravityforms.com\/author\/stevehenty\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","_links":{"self":[{"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/posts\/7256"}],"collection":[{"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/users\/1533"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/comments?post=7256"}],"version-history":[{"count":0,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/posts\/7256\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/media?parent=7256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/categories?post=7256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gravityforms.com\/wp-json\/wp\/v2\/tags?post=7256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}